package com.Nuyoah.demo01.controller;

import com.Nuyoah.demo01.entity.Menu;
import com.Nuyoah.demo01.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;


    /* 1. 新增菜单 */
    @PostMapping("/add")
    public boolean add(@RequestBody Menu menu) {
        return menuService.save(menu);
    }

    /* 2. 修改菜单 */
    @PostMapping("/update")
    public boolean update(@RequestBody Menu menu) {
        return menuService.updateById(menu);
    }

    /* 3. 逻辑删除菜单 */
    @PostMapping("/delete")
    public boolean delete(@RequestParam Long id) {
        return menuService.removeById(id);
    }

    /* 4. 获取单条菜单详情 */
    @PostMapping("/detail")
    public Menu detail(@RequestParam Long id) {
        return menuService.getById(id);
    }

    /* 5. 获取树形菜单列表 */
    @PostMapping("/list")
    public List<Menu> list() {
        return menuService.buildMenuTree();
    }
}
